//let panel = document.querySelector(".panel")
function ww() {
    $.get('http://chst.vip:1234/api/getcategorytitle')
        .then(res => {
            let tt = ''
            let result = res.result
            console.log(result);
            result.forEach((item, index) => {
                ld(index)
                tt += `
                  <li class="liIndex" class="">
                        <div class="smallTitle">
                           <span>${item.title}</span>
                           <i class="fr">▼</i>
                         </div>
                         <div class="none">                    
                            <div class="context"> </div>                          
                        </div>  
                    </li>
                       `
            })
            $('.uu').append(tt)
            $('.smallTitle').click(function () {
                $('.none').stop().hide(200)
                $(this).next().stop().slideToggle(200);
            }
            )
           
            $('.context').click ( function (e) {
                if (e.target.localName) {
                    let _this = e.target;
                    console.log(_this)
        
                    //获取当前li标签的productid
        
                    let id = _this.getAttribute('categoryid')
        
                    location.href = './bjsslist.html?categoryid=' + id
                }
            })

        })

    function ld(ldindex) {
        let hh = ''
        $.get(`http://chst.vip:1234/api/getcategory?titleid=${ldindex}`)
            .then(ress => {
                console.log(ress);
                ress.result.forEach(item => {
                    hh += `
                    <span category=${item.category} categoryid=${item.categoryId}><a categoryid=${item.categoryId}>${item.category}</a></span>
                    `
                })
                $('.context').eq(ldindex).append(hh)
            })
    }
}
ww()



/* panel.addEventListener("click", function (e) {
    let _this = e.target
    let panel_content = $(".panel-content")
    if (_this.getAttribute("flag") === '0') {
        _this.setAttribute("flag", "1")
        if (_this.className = "panel-heading") {
            $(_this).next().slideDown(200)
            $(_this).next().siblings('div.panel-content.hide').slideUp(200)
            $(_this).siblings('div.panel-heading').attr("flag", "0")
        }
    } else if (_this.getAttribute("flag") === '1') {
        _this.setAttribute("flag", "0")
        if (_this.className = "panel-heading") {
            $(_this).next().slideUp(200)
            // $(_this).next().siblings('div.panel-content.hide').slideDown(200)
            // $(_this).siblings('div.panel-heading').attr("flag", "1")
        }
    }
}) */
/* let smallTitle=$('.smallTitle').get(0)
console.log(smallTitle) */

/* panel.addEventListener("click", function (e) {
    let _this = e.target;
    let categoryid;
    if (_this.className === "productcategory") {
        categoryid = _this.getAttribute("categoryid")
        // console.log(categoryid);
        location.href = "./bjsslist.html?categoryid=" + categoryid
    }

})  */